﻿package main

import (
    "fmt"
    "sync/atomic"
)

func main() {
    pipe := make(chan int32, 1000)
    var count int32 = 0
    for i := 0; i < 1000; i++ {
        go func(n *int32, p chan int32){
            //*n++
            //p <- *n
            p <- atomic.AddInt32(n, 1)  // 计算+赋值作为原子操作
        }(&count, pipe)
    }
    for i := 0; i < 1000; i++ {
        res := <- pipe
        fmt.Println(res)
    }
}